<template>
  <div class="role-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>角色管理</span>
          <el-button type="primary" @click="handleAdd">新增角色</el-button>
        </div>
      </template>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="name" label="角色名称" width="180" />
        <el-table-column prop="code" label="角色编码" width="180" />
        <el-table-column prop="description" label="描述" />
        <el-table-column label="操作" width="220">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="small"
              type="primary"
              @click="handlePermission(scope.$index, scope.row)"
              >分配权限</el-button
            >
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
const tableData = [
  {
    name: '超级管理员',
    code: 'admin',
    description: '拥有所有权限'
  },
  {
    name: '普通用户',
    code: 'user',
    description: '拥有部分权限'
  }
]

const handleAdd = () => {
  console.log('Add new role')
}

const handleEdit = (index: number, row: any) => {
  console.log(index, row)
}

const handlePermission = (index: number, row: any) => {
  console.log('Assign permissions for', index, row)
}

const handleDelete = (index: number, row: any) => {
  console.log(index, row)
}
</script>

<style scoped>
.role-container {
  padding: 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
